package com.eian.boot.rabbit;

import com.eian.boot.rabbit.core.sender.RabbitTemplateProxy;
import com.eian.boot.rabbit.model.Message;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class RabbitHelper {
    private final RabbitTemplateProxy rabbitProxy;

    public RabbitHelper(RabbitTemplateProxy rabbitProxy) {
        this.rabbitProxy = rabbitProxy;
    }

    public void send(String exchange, String routingKey, Message<?> message) {
        if (Objects.nonNull(message.deliveryTime())) {
            message = message.withDeliveryTime(System.currentTimeMillis() + message.deliveryTime());
        }
        rabbitProxy.send(exchange, routingKey, message);
    }
}
